package world3d;

import java.util.ArrayList;

import javax.media.j3d.BranchGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;

public class Floor {
	
	public final static int FLOOR_LEN = 80;
	
	private BranchGroup floorBg;
	
	private Color3f blue = new Color3f(1.0f, 0.0f, 0.0f);
	private Color3f green = new Color3f(0.0f, 0.0f, 0.0f);
	
	public Floor(){
		ArrayList<Point3f> blueCoords = new ArrayList<Point3f>();
		ArrayList<Point3f> greenCoords = new ArrayList<Point3f>();
		
		floorBg = new BranchGroup();
		
		for(int z = -(FLOOR_LEN / 2); z <= (FLOOR_LEN/2 -1); z++){
			boolean isBlue = (z % 2 == 0)? true : false;
			
			for(int x = -(FLOOR_LEN / 2); x <= (FLOOR_LEN/2 - 1); x++){
				if(isBlue){
					createCoords(x, z, blueCoords);
				}else{
					createCoords(x, z, greenCoords);
				}
				isBlue = !isBlue;
			}
		}
		
		floorBg.addChild(new ColouredTiles(blueCoords, blue));
		floorBg.addChild(new ColouredTiles(greenCoords, green));
	}
	
	private void createCoords(int x, int z, ArrayList<Point3f> coords){
		Point3f p1 = new Point3f(x, 0.0f, z + 1.0f);
		Point3f p2 = new Point3f(x + 1.0f, 0.0f, z + 1.0f);
		Point3f p3 = new Point3f(x + 1.0f, 0.0f, z);
		Point3f p4 = new Point3f(x, 0.0f, z);
		
		coords.add(p1);
		coords.add(p2);
		coords.add(p3);
		coords.add(p4);
	}
	
	protected void setFloor(BranchGroup bg){
		this.floorBg = bg;
	}
	
	public BranchGroup getFloor(){
		return floorBg;
	}
}
